package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.LinkBean;
import com.project.service.ILinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("link")
public class LinkController {
    @Autowired
    private ILinkService service;

    @RequestMapping("findAll")
    public String cut(@RequestParam(value = "pageNum" ,defaultValue = "1") int pageNum, HttpServletRequest req){
        PageInfo<LinkBean> pgInfo = service.findAll(pageNum);
        req.setAttribute("pgInfo",pgInfo);
        return "/html/main.html";
    }
    @RequestMapping("add")
    public String add(LinkBean link){
        service.add(link);
        return "redirect:/link/findAll";
    }
    @RequestMapping("del")
    public String del(int id){
        service.delId(id);
        return "redirect:/link/findAll";
    }
    @RequestMapping("findById")
    public String findById(int id,HttpServletRequest req){
       LinkBean link = service.findById(id);
       req.setAttribute("link",link);
        return "/html/update.html";
    }
    @RequestMapping("update")
    public String update(int id,String phone){
        service.update(id,phone);
        return "redirect:/link/findAll";
    }
}
